package com.xm.shop.app.api.controller;

import com.xm.shop.pojo.entity.Order;
import com.xm.shop.pojo.qo.OrderAddQO;
import com.xm.shop.pojo.vo.RespResult;
import com.xm.shop.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ludi
 * @date:2020/9/1 10:00
 * @description:订单业务控制层
 */
@Controller
@RestController
@RequestMapping("/order")
@Api(tags = "订单业务接口")
public class OrderController extends BaseController {
    @Autowired
    private OrderService orderService;

    @PostMapping("/addOrder")
    @ApiOperation("添加订单")
    public RespResult addOrder(@RequestBody OrderAddQO orderAddQO){
        OrderAddQO newOrderAddQO = new OrderAddQO(orderAddQO.getUserId(), orderAddQO.getAddressId()
                , orderAddQO.getIntegral(), orderAddQO.getTotalPrice());
        orderService.addOrder(newOrderAddQO);
        return returnRespWithSuccess(newOrderAddQO.getOrderId());
    }

    @GetMapping("/selectOrdersByUserId")
    @ApiOperation("查看所有订单")
    public RespResult selectOrdersByUserId(Integer userId){
        List<Order> orderList = orderService.selectOrdersByUserId(userId);
        return returnRespWithSuccess(orderList);
    }

    @GetMapping("/selectOrderByOrderId")
    @ApiOperation("查看订单详情(地址信息)")
    public RespResult selectOrderByOrderId(Integer orderId){
        Order order = orderService.selectByOrderId(orderId);
        System.out.println(order);
        return returnRespWithSuccess(order);
    }
}
